/*
 * @Description:
 * @version:
 * @Author: 尹鹏孝
 * @Date: 2023-08-05 09:47:06
 * @LastEditors: 尹鹏孝
 * @LastEditTime: 2023-10-18 08:59:00
 */
import { ArgumentsHost, Catch, ExceptionFilter,HttpException  } from '@nestjs/common';
import { Request, Response } from 'express';
import * as moment from 'moment';
@Catch()
export class HttpExceptionFilter <T> implements ExceptionFilter {
  catch(exception: HttpException, host: ArgumentsHost) {
    const ctx = host.switchToHttp();
    const response = ctx.getResponse<Response>();
    const request = ctx.getRequest<Request>();
    const status = exception.getStatus();
    try {
      response
      .status(status)
      .json({
        statusCode: status,
        timestamp:moment( new Date()).format("YYYY-MM-DD HH:mm:ss"),
        path: request.url,
      });
    } catch (error) {
      console.log(error)
    }

  }
}
